package cn.gok.homework;

import java.util.Random;

import java.util.Scanner;


public class homework1 {

        public static void main(String[] args) {
            产生并输出随机密码();
        }

        private static void 产生并输出随机密码() {
            System.out.println("请输入密码长度：大于等于6");
            int n = new Scanner(System.in).nextInt();
            if (n >= 6) {
                //1 密码长度固定为n
                //2 必须同时包含大写字母及数字
                //int x = new Random().nextInt(26); //产生[0,25]的随机数
                //3 输出密码
                char cs[] = new char[n];
//        todo:?????
                for (int i = 0; i < n; i++) {
                    int x = new Random().nextInt(2);
                    if (x == 1) {
                        int num = new Random().nextInt(10);
                        cs[i] = (char) (num + '0');
                    } else {
                        int chars = new Random().nextInt(26);
                        cs[i] = (char) ('A' + chars);
                    }
                }

                String str = new String(cs);
                System.out.println(str);
            } else {
                System.out.println("输入有误,请输入的密码长度大于等于6");
            }
        }
    }

